package lingnan.cn.edu.Table;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import lingnan.cn.edu.BaseAndImpl.MilkManageService;
import lingnan.cn.edu.User.Milkteainf;
import lingnan.cn.edu.service.MilkManageServiceImpl;

public class MilkManageTableModel extends AbstractTableModel{
	private String [] columnName = {"产品编号","奶茶名称","价格","图片路径","类型"};
	
	private MilkManageService milkservice = new MilkManageServiceImpl();
	
	private List<Milkteainf> milkteas;
	
	public void query() {
		milkteas = milkservice.query();
	}
	
	public void findMilkTea(String mteaname,String type) {
		milkteas = milkservice.findMilkTea(mteaname,type);
	}
	@Override
	public int getRowCount() {
		return milkteas.size();
	}

	@Override
	public int getColumnCount() {
		return columnName.length;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Milkteainf milktea = milkteas.get(rowIndex);
		if (columnIndex == 1) {
			return milktea.getName();
		} else if (columnIndex == 0) {
			return milktea.getId();
		} else if (columnIndex == 2) {
			return milktea.getPrice();
		} else if (columnIndex == 3) {
			return milktea.getImg();
		} else if (columnIndex == 4) {
			return milktea.getType();
		} else {
			return null;
		}
	}
	
	@Override
	public String getColumnName(int column) {
		return columnName[column];
	}
}
